In [1]:
import pandas as pd
import matplotlib.pyplot as plt 
import plotly.express as px

%matplotlib inline

Debemos mdificar el conjunto de datos creado en la PRAC 1 para omitir algunos errores con los nombres de los paises:

In [2]:
covid = pd.read_csv("owid-covid-data.csv")

columns_names = ['iso_code', 'continent', 'location', 'total_cases', 'total_deaths',
       'total_cases_per_million', 'total_deaths_per_million', 'stringency_index',
       'population', 'population_density', 'median_age', 'aged_65_older',
       'aged_70_older', 'gdp_per_capita', 'extreme_poverty',
       'cardiovasc_death_rate', 'diabetes_prevalence', 'female_smokers',
       'male_smokers', 'hospital_beds_per_thousand',
       'life_expectancy', 'human_development_index']

id_deaths = covid.groupby("location")['total_deaths_per_million'].transform(max) == covid['total_deaths_per_million']
covid_max_detahts = covid[id_deaths]
covid_max_detahts = covid_max_detahts[columns_names]
covid_max_detahts = covid_max_detahts.drop_duplicates(subset = ['location'], keep = 'last')


health_expenditure = pd.read_csv("health_expenditure.csv")
health_expenditure = health_expenditure[['FactValueNumeric', 'Location']]
health_expenditure.columns = ["health_expenditure", "location"]
health_expenditure.loc[health_expenditure["location"] == "United Kingdom of Great Britain and Northern Ireland",
                       "location"] = "United Kingdom"
health_expenditure.loc[health_expenditure["location"] == "United States of America",
                       "location"] = "United States"
health_expenditure.loc[health_expenditure["location"] == "Republic of Korea",
                       "location"] = "South Korea"
health_expenditure.loc[health_expenditure["location"] == "Russian Federation",
                       "location"] = "Russia"
health_expenditure.loc[health_expenditure["location"] == "Iran (Islamic Republic of)",
                       "location"] = "Iran"
health_expenditure.loc[health_expenditure["location"] == "Bolivia (Plurinational State of)",
                       "location"] = "Bolivia"
health_expenditure.loc[health_expenditure["location"] == "Brunei Darussalam",
                       "location"] = "Brunei"
health_expenditure.loc[health_expenditure["location"] == "Côte d’Ivoire",
                       "location"] = "Cote d'Ivoire"
health_expenditure.loc[health_expenditure["location"] == "Democratic Republic of the Congo",
                       "location"] = "Democratic Republic of Congo"
health_expenditure.loc[health_expenditure["location"] == "Lao People's Democratic Republic",
                       "location"] = "Laos"
health_expenditure.loc[health_expenditure["location"] == "Micronesia (Federated States of)",
                       "location"] = "Micronesia (country)"
health_expenditure.loc[health_expenditure["location"] == "Republic of Moldova",
                       "location"] = "Moldova"
health_expenditure.loc[health_expenditure["location"] == "Syrian Arab Republic",
                       "location"] = "Syria"
health_expenditure.loc[health_expenditure["location"] == "Timor-Leste",
                       "location"] = "Timor"
health_expenditure.loc[health_expenditure["location"] == "United Republic of Tanzania",
                       "location"] = "Tanzania"
health_expenditure.loc[health_expenditure["location"] == "Venezuela (Bolivarian Republic of)",
                       "location"] = "Venezuela"
health_expenditure.loc[health_expenditure["location"] == "Viet Nam",
                       "location"] = "Vietnam"




private_health_percent = pd.read_csv("private_health_percent.csv")
private_health_percent = private_health_percent[['FactValueNumeric', 'Location']]
private_health_percent.columns = ["private_health_percent", "location"]
private_health_percent.loc[private_health_percent["location"] == "United Kingdom of Great Britain and Northern Ireland",
                       "location"] = "United Kingdom"
private_health_percent.loc[private_health_percent["location"] == "United States of America",
                       "location"] = "United States"
private_health_percent.loc[private_health_percent["location"] == "Republic of Korea",
                       "location"] = "South Korea"
private_health_percent.loc[private_health_percent["location"] == "Russian Federation",
                       "location"] = "Russia"
private_health_percent.loc[private_health_percent["location"] == "Iran (Islamic Republic of)",
                       "location"] = "Iran"
private_health_percent.loc[private_health_percent["location"] == "Bolivia (Plurinational State of)",
                       "location"] = "Bolivia"
private_health_percent.loc[private_health_percent["location"] == "Brunei Darussalam",
                       "location"] = "Brunei"
private_health_percent.loc[private_health_percent["location"] == "Côte d’Ivoire",
                       "location"] = "Cote d'Ivoire"
private_health_percent.loc[private_health_percent["location"] == "Democratic Republic of the Congo",
                       "location"] = "Democratic Republic of Congo"
private_health_percent.loc[private_health_percent["location"] == "Lao People's Democratic Republic",
                       "location"] = "Laos"
private_health_percent.loc[private_health_percent["location"] == "Micronesia (Federated States of)",
                       "location"] = "Micronesia (country)"
private_health_percent.loc[private_health_percent["location"] == "Republic of Moldova",
                       "location"] = "Moldova"
private_health_percent.loc[private_health_percent["location"] == "Syrian Arab Republic",
                       "location"] = "Syria"
private_health_percent.loc[private_health_percent["location"] == "Timor-Leste",
                       "location"] = "Timor"
private_health_percent.loc[private_health_percent["location"] == "United Republic of Tanzania",
                       "location"] = "Tanzania"
private_health_percent.loc[private_health_percent["location"] == "Venezuela (Bolivarian Republic of)",
                       "location"] = "Venezuela"
private_health_percent.loc[private_health_percent["location"] == "Viet Nam",
                       "location"] = "Vietnam"

medical_doctors = pd.read_csv("medical_doctors.csv")
medical_doctors = medical_doctors[['Value', 'Location']]
medical_doctors.columns = ["medical_doctors_per10k", "location"]
medical_doctors.loc[medical_doctors["location"] == "United Kingdom of Great Britain and Northern Ireland",
                       "location"] = "United Kingdom"
medical_doctors.loc[medical_doctors["location"] == "United States of America",
                       "location"] = "United States"
medical_doctors.loc[medical_doctors["location"] == "Republic of Korea",
                       "location"] = "South Korea"
medical_doctors.loc[medical_doctors["location"] == "Russian Federation",
                       "location"] = "Russia"
medical_doctors.loc[medical_doctors["location"] == "Iran (Islamic Republic of)",
                       "location"] = "Iran"
medical_doctors.loc[medical_doctors["location"] == "Bolivia (Plurinational State of)",
                       "location"] = "Bolivia"
medical_doctors.loc[medical_doctors["location"] == "Brunei Darussalam",
                       "location"] = "Brunei"
medical_doctors.loc[medical_doctors["location"] == "Côte d’Ivoire",
                       "location"] = "Cote d'Ivoire"
medical_doctors.loc[medical_doctors["location"] == "Democratic Republic of the Congo",
                       "location"] = "Democratic Republic of Congo"
medical_doctors.loc[medical_doctors["location"] == "Lao People's Democratic Republic",
                       "location"] = "Laos"
medical_doctors.loc[medical_doctors["location"] == "Micronesia (Federated States of)",
                       "location"] = "Micronesia (country)"
medical_doctors.loc[medical_doctors["location"] == "Republic of Moldova",
                       "location"] = "Moldova"
medical_doctors.loc[medical_doctors["location"] == "Syrian Arab Republic",
                       "location"] = "Syria"
medical_doctors.loc[medical_doctors["location"] == "Timor-Leste",
                       "location"] = "Timor"
medical_doctors.loc[medical_doctors["location"] == "United Republic of Tanzania",
                       "location"] = "Tanzania"
medical_doctors.loc[medical_doctors["location"] == "Venezuela (Bolivarian Republic of)",
                       "location"] = "Venezuela"
medical_doctors.loc[medical_doctors["location"] == "Viet Nam",
                       "location"] = "Vietnam"

nurses = pd.read_csv("nursing.csv")
nurses = nurses[['Value', 'Location']]
nurses.columns = ["nursing_midwifery_per10k", "location"]
nurses.loc[nurses["location"] == "United Kingdom of Great Britain and Northern Ireland",
                       "location"] = "United Kingdom"
nurses.loc[nurses["location"] == "United States of America",
                       "location"] = "United States"
nurses.loc[nurses["location"] == "Republic of Korea",
                       "location"] = "South Korea"
nurses.loc[nurses["location"] == "Russian Federation",
                       "location"] = "Russia"
nurses.loc[nurses["location"] == "Iran (Islamic Republic of)",
                       "location"] = "Iran"
nurses.loc[nurses["location"] == "Bolivia (Plurinational State of)",
                       "location"] = "Bolivia"
nurses.loc[nurses["location"] == "Brunei Darussalam",
                       "location"] = "Brunei"
nurses.loc[nurses["location"] == "Côte d’Ivoire",
                       "location"] = "Cote d'Ivoire"
nurses.loc[nurses["location"] == "Democratic Republic of the Congo",
                       "location"] = "Democratic Republic of Congo"
nurses.loc[nurses["location"] == "Lao People's Democratic Republic",
                       "location"] = "Laos"
nurses.loc[nurses["location"] == "Micronesia (Federated States of)",
                       "location"] = "Micronesia (country)"
nurses.loc[nurses["location"] == "Republic of Moldova",
                       "location"] = "Moldova"
nurses.loc[nurses["location"] == "Syrian Arab Republic",
                       "location"] = "Syria"
nurses.loc[nurses["location"] == "Timor-Leste",
                       "location"] = "Timor"
nurses.loc[nurses["location"] == "United Republic of Tanzania",
                       "location"] = "Tanzania"
nurses.loc[nurses["location"] == "Venezuela (Bolivarian Republic of)",
                       "location"] = "Venezuela"
nurses.loc[nurses["location"] == "Viet Nam",
                       "location"] = "Vietnam"


total_vac = pd.read_csv("vaccination-data.csv")
total_vac = total_vac[['COUNTRY', 'TOTAL_VACCINATIONS_PER100', 'PERSONS_FULLY_VACCINATED_PER100']]
total_vac.columns = ["location", "TOTAL_VACCINATIONS_PER100", "PERSONS_FULLY_VACCINATED_PER100"]
total_vac.loc[total_vac["location"] == "The United Kingdom", "location"] = "United Kingdom"
total_vac.loc[total_vac["location"] == "United States of America",
                       "location"] = "United States"
total_vac.loc[total_vac["location"] == "Republic of Korea",
                       "location"] = "South Korea"
total_vac.loc[total_vac["location"] == "Russian Federation",
                       "location"] = "Russia"
total_vac.loc[total_vac["location"] == "Iran (Islamic Republic of)",
                       "location"] = "Iran"
total_vac.loc[total_vac["location"] == "Bolivia (Plurinational State of)",
                       "location"] = "Bolivia"
total_vac.loc[total_vac["location"] == "Brunei Darussalam",
                       "location"] = "Brunei"
total_vac.loc[total_vac["location"] == "Côte d’Ivoire",
                       "location"] = "Cote d'Ivoire"
total_vac.loc[total_vac["location"] == "Democratic Republic of the Congo",
                       "location"] = "Democratic Republic of Congo"
total_vac.loc[total_vac["location"] == "Lao People's Democratic Republic",
                       "location"] = "Laos"
total_vac.loc[total_vac["location"] == "Micronesia (Federated States of)",
                       "location"] = "Micronesia (country)"
total_vac.loc[total_vac["location"] == "Republic of Moldova",
                       "location"] = "Moldova"
total_vac.loc[total_vac["location"] == "Syrian Arab Republic",
                       "location"] = "Syria"
total_vac.loc[total_vac["location"] == "Timor-Leste",
                       "location"] = "Timor"
total_vac.loc[total_vac["location"] == "United Republic of Tanzania",
                       "location"] = "Tanzania"
total_vac.loc[total_vac["location"] == "Venezuela (Bolivarian Republic of)",
                       "location"] = "Venezuela"
total_vac.loc[total_vac["location"] == "Viet Nam",
                       "location"] = "Vietnam"


excess_mortality = pd.read_csv("excess_mortality_economist_estimates.csv", decimal=".")
excess_mortality = excess_mortality[["country", "cumulative_estimated_daily_excess_deaths_per_100k"]]
excess_mortality = pd.DataFrame(excess_mortality.groupby('country')['cumulative_estimated_daily_excess_deaths_per_100k'].last())
excess_mortality = excess_mortality.reset_index(drop=False)
excess_mortality.columns = ["location", "cumulative_estimated_daily_excess_deaths_per_100k"]



df = pd.merge(covid_max_detahts, health_expenditure)
df_2 = pd.merge(df, private_health_percent)
df_3 = pd.merge(df_2, medical_doctors)
df_4 = pd.merge(df_3, nurses)
df_5 = pd.merge(df_4, total_vac)
created_df = pd.merge(df_5, excess_mortality)
created_df.head()
Out[2]:
iso_code continent location total_cases total_deaths total_cases_per_million total_deaths_per_million stringency_index population population_density ... hospital_beds_per_thousand life_expectancy human_development_index health_expenditure private_health_percent medical_doctors_per10k nursing_midwifery_per10k TOTAL_VACCINATIONS_PER100 PERSONS_FULLY_VACCINATED_PER100 cumulative_estimated_daily_excess_deaths_per_100k
0 AFG Asia Afghanistan 178901.0 7683.0 4491.002 192.869 NaN 39835428.0 54.422 ... 0.50 64.83 0.511 65.81 79.40 2.54 4.46 15.377 11.912 183.902369
1 ALB Europe Albania 275177.0 3496.0 95782.569 1216.874 NaN 2872934.0 104.871 ... 2.89 78.57 0.795 274.90 44.66 18.75 60.46 98.200 43.305 614.716262
2 DZA Africa Algeria 265782.0 6875.0 5957.017 154.091 NaN 44616626.0 17.348 ... 1.90 76.88 0.748 248.20 34.96 17.19 15.48 34.676 14.780 205.241942
3 AND Europe Andorra 39713.0 155.0 513392.973 2003.775 11.11 77354.0 163.755 ... NaN 83.73 0.868 2744.00 30.51 33.33 40.13 197.100 70.108 255.959753
4 AGO Africa Angola 99287.0 1900.0 2925.919 55.992 37.04 33933611.0 23.890 ... NaN 61.15 0.581 71.33 55.61 2.14 4.08 54.453 19.253 143.430667

5 rows × 29 columns

In [3]:
created_df.shape
Out[3]:
(183, 29)

Cargamos los datos de la serie temporal original:

In [4]:
time_serie_df = pd.read_csv("owid-covid-data.csv")
time_serie_df.head()
Out[4]:
iso_code continent location date total_cases new_cases new_cases_smoothed total_deaths new_deaths new_deaths_smoothed ... female_smokers male_smokers handwashing_facilities hospital_beds_per_thousand life_expectancy human_development_index excess_mortality_cumulative_absolute excess_mortality_cumulative excess_mortality excess_mortality_cumulative_per_million
0 AFG Asia Afghanistan 2020-02-24 5.0 5.0 NaN NaN NaN NaN ... NaN NaN 37.746 0.5 64.83 0.511 NaN NaN NaN NaN
1 AFG Asia Afghanistan 2020-02-25 5.0 0.0 NaN NaN NaN NaN ... NaN NaN 37.746 0.5 64.83 0.511 NaN NaN NaN NaN
2 AFG Asia Afghanistan 2020-02-26 5.0 0.0 NaN NaN NaN NaN ... NaN NaN 37.746 0.5 64.83 0.511 NaN NaN NaN NaN
3 AFG Asia Afghanistan 2020-02-27 5.0 0.0 NaN NaN NaN NaN ... NaN NaN 37.746 0.5 64.83 0.511 NaN NaN NaN NaN
4 AFG Asia Afghanistan 2020-02-28 5.0 0.0 NaN NaN NaN NaN ... NaN NaN 37.746 0.5 64.83 0.511 NaN NaN NaN NaN

5 rows × 67 columns

In [5]:
time_serie_df.shape
Out[5]:
(183348, 67)
In [6]:
from dash import dcc, html, Dash
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import numpy as np
from plotly.subplots import make_subplots
import plotly.express as px


plot1_df = time_serie_df[["location", "date", "new_cases", "continent"]].dropna(axis=0)
plot1_df = plot1_df[plot1_df.new_cases != 0]

plot2_df = time_serie_df[["location", "date", "new_deaths", "continent"]].dropna(axis=0)
plot2_df = plot2_df[plot2_df.new_deaths != 0]

plot3_df = time_serie_df[["location", "date", "excess_mortality", "continent"]].dropna(axis=0)
#plot3_df = plot3_df[plot3_df.excess_mortality_cumulative != 0]

plot4_df = time_serie_df[["location", "date", "people_vaccinated_per_hundred", "continent"]].dropna(axis=0)

plot5_df = time_serie_df[["location", "date", "new_deaths_per_million", "continent"]].dropna(axis=0)

plot6_df = time_serie_df[["location", "date", "icu_patients", "continent"]].dropna(axis=0)
     

app = Dash()
figs = ['new cases evolution in the world', 'deaths evolution in the world', 'excess mortality evolution in the world',
        'people vaccinated per hundred evolution', 'deaths per million evolution in the world',
        'icu patients evolution in the world']

app.layout = html.Div([
    html.Div([
        dcc.Graph(id='plot'),

        html.Div([
            dcc.Dropdown(
                id='variables',
                options=[{'label': i, 'value': i} for i in figs],
                value=figs[0]
            ),
            dcc.Checklist(
                id="checklist",
                options=['Asia', 'Europe', 'Africa', 'North America', 'South America', 'Oceania'],
                value=["Europe"],
                inline=True
            ),
      ])
    ])
])

@app.callback(
    Output('plot', 'figure'),
    [Input('variables', 'value'),  Input('checklist', 'value')])

def update_graph(fig_name, continents):
    if fig_name == 'new cases evolution in the world':
        mask = plot1_df.continent.isin(continents)
        if len(continents)==1:
            titlle_add = str(continents[0])
        elif len(continents)>1:
            titlle_add = ''.join(str(x) + ", " for x in continents)
            titlle_add = titlle_add[:-2]
        else:
            titlle_add = "None"
        fig1 = px.line(plot1_df[mask], x="date", y="new_cases", color='location',
              hover_data={"date": "|%B %d, %Y"},
              title='new cases evolution in {}'.format(titlle_add),
              height=800)
        fig1.update_xaxes(
            dtick="M1",
            tickformat="%b\n%Y")

        fig1.update_layout(
            xaxis_title="<b> date <b>",
            yaxis_title="<b> new_cases <b>",
            legend_title="<b> Countries <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig1

    if fig_name == 'deaths evolution in the world':
        mask = plot2_df.continent.isin(continents)
        if len(continents)==1:
            titlle_add = str(continents[0])
        elif len(continents)>1:
            titlle_add = ''.join(str(x) + ", " for x in continents)
            titlle_add = titlle_add[:-2]
        else:
            titlle_add = "None"
        fig2 = px.line(plot2_df[mask], x="date", y="new_deaths", color='location',
              hover_data={"date": "|%B %d, %Y"},
              title='deaths evolution in {}'.format(titlle_add),
              height=800)
        fig2.update_xaxes(
            dtick="M1",
            tickformat="%b\n%Y")


        fig2.update_layout(
            xaxis_title="<b> date <b>",
            yaxis_title="<b> excess_mortality_cummulative <b>",
            legend_title="<b> Countries <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        ) 
        return fig2

    if fig_name == 'excess mortality evolution in the world':
        mask = plot3_df.continent.isin(continents)
        if len(continents)==1:
            titlle_add = str(continents[0])
        elif len(continents)>1:
            titlle_add = ''.join(str(x) + ", " for x in continents)
            titlle_add = titlle_add[:-2]
        else:
            titlle_add = "None"
        fig3 = px.line(plot3_df[mask], x="date", y="excess_mortality", color='location',
               hover_data={"date": "|%B %d, %Y"},
               title='excess mortality evolution in {}'.format(titlle_add),
               height=800)
        fig3.update_xaxes(
            dtick="M1",
            tickformat="%b\n%Y")
        fig3.update_layout(
            xaxis_title="<b> date <b>",
            yaxis_title="<b> excess_mortality <b>",
            legend_title="<b> Countries <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )  
        return fig3
    
    if fig_name == 'people vaccinated per hundred evolution':
        mask = plot4_df.continent.isin(continents)
        if len(continents)==1:
            titlle_add = str(continents[0])
        elif len(continents)>1:
            titlle_add = ''.join(str(x) + ", " for x in continents)
            titlle_add = titlle_add[:-2]
        else:
            titlle_add = "None"
        fig4 = px.line(plot4_df[mask], x="date", y="people_vaccinated_per_hundred", color='location',
               hover_data={"date": "|%B %d, %Y"},
               title='vaccinated evolution in {}'.format(titlle_add),
               height=800)
        fig4.update_xaxes(
            dtick="M1",
            tickformat="%b\n%Y")
        fig4.update_layout(
            xaxis_title="<b> date <b>",
            yaxis_title="<b> people_vaccinated <b>",
            legend_title="<b> Countries <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )  
        return fig4
    
    if fig_name == 'deaths per million evolution in the world':
        mask = plot5_df.continent.isin(continents)
        if len(continents)==1:
            titlle_add = str(continents[0])
        elif len(continents)>1:
            titlle_add = ''.join(str(x) + ", " for x in continents)
            titlle_add = titlle_add[:-2]
        else:
            titlle_add = "None"
        fig5 = px.line(plot5_df[mask], x="date", y="new_deaths_per_million", color='location',
               hover_data={"date": "|%B %d, %Y"},
               title='deaths per million evolution in {}'.format(titlle_add),
               height=800)
        fig5.update_xaxes(
            dtick="M1",
            tickformat="%b\n%Y")
        fig5.update_layout(
            xaxis_title="<b> date <b>",
            yaxis_title="<b> new_deaths_per_million <b>",
            legend_title="<b> Countries <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )  
        return fig5
    
    if fig_name == 'icu patients evolution in the world':
        mask = plot6_df.continent.isin(continents)
        if len(continents)==1:
            titlle_add = str(continents[0])
        elif len(continents)>1:
            titlle_add = ''.join(str(x) + ", " for x in continents)
            titlle_add = titlle_add[:-2]
        else:
            titlle_add = "None"
        fig6 = px.line(plot6_df[mask], x="date", y="icu_patients", color='location',
               hover_data={"date": "|%B %d, %Y"},
               title='icu patients evolution in {}'.format(titlle_add),
               height=800)
        fig6.update_xaxes(
            dtick="M1",
            tickformat="%b\n%Y")
        fig6.update_layout(
            xaxis_title="<b> date <b>",
            yaxis_title="<b> icu_patients <b>",
            legend_title="<b> Countries <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )  
        return fig6
        
app.run_server(debug=True,
           use_reloader=False
          ) 
Dash is running on http://127.0.0.1:8050/

 * Serving Flask app '__main__' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on

Hacemos una primera inspecciónd el número de fallecidos en todos los países, comprobamos que hay registros muy dispares, países en los que quizás los datos no tengan la misma fiabilidad que en otros, normalmente los países más desarrollados tendrán más facilidad para recabar datos, por otra parte también se jercerá mayor control sobre los mismos:

In [7]:
fig = px.choropleth(created_df, locations='iso_code', color='total_deaths_per_million', hover_name='location', 
                    color_continuous_scale=px.colors.sequential.Plasma, projection='natural earth')
fig.show() 

Por eso he decidido seleccionar los países pertenecientes a la OCDE, con las economias más avanzadas y suponiendo una mayor fiabilidad: (añadiré algunas economias importantes, Rusia, China, Iran, Ucrania, Brasil

In [8]:
list_ocde_plus = ["Austria", "Australia", "Belgium", "Canada", "Chile", "Colombia",
             "Costa Rica", "Czechia", "Denmark", "Estonia", "Finland",
             "France", "Germany", "Greece", "Hungary", "Iceland", "Ireland",
             "Israel", "Italy", "Japan", "South Korea", "Latvia", "Lithuania", "Luxembourg",
             "Mexico", "Netherlands", "New Zealand", "Norway", "Poland", "Portugal",
             "Slovakia", "Slovenia", "Spain", "Sweden", "Switzerland", "Turkey",
             "United Kingdom", "United States", "China", "Russia", "Iran", "Ukraine", "Brazil"]
In [9]:
test = created_df[created_df["location"].isin(list_ocde_plus)]
test.shape
Out[9]:
(43, 29)

El gasto medico está expresado en US$ per capita

In [10]:
from dash import dcc, html, Dash
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import numpy as np
from plotly.subplots import make_subplots
import plotly.express as px

app = Dash()
figs = ['gdp per capita VS total deaths per million', 'gdp per capita VS total deaths per million and health expenditure',
        'health expenditure VS total deaths per million', 'population density VS total deaths per million',
        'health expenditure VS private health expenditure',
        'hospital beds per thousand VS cumulative_estimated_daily_excess_deaths',
        'medical_doctors_per10k VS cumulative_estimated_daily_excess_deaths',
        'nursing_midwifery_per10k VS cumulative_estimated_daily_excess_deaths',
        'aged_70_older VS cumulative_estimated_daily_excess_deaths',
        'population_density VS cumulative_estimated_daily_excess_deaths',
        'male_smokers VS cumulative_estimated_daily_excess_deaths',
        'TOTAL_VACCINATIONS_PER100 VS cumulative_estimated_daily_excess_deaths',
        'private_health_percent VS cumulative_estimated_daily_excess_deaths',
        'cardiovasc_death_rate VS cumulative_estimated_daily_excess_deaths',
        'diabetes_prevalence VS cumulative_estimated_daily_excess_deaths',
        'human_development_index VS cumulative_estimated_daily_excess_deaths']

app.layout = html.Div([
    html.Div([
        dcc.Graph(id='plot'),

        html.Div([
            dcc.Dropdown(
                id='variables',
                options=[{'label': i, 'value': i} for i in figs],
                value=figs[0]
            ),
            dcc.Checklist(
                id="checklist",
                options=['Asia', 'Europe', 'North America', 'South America', 'Oceania'],
                value=["Europe"],
                inline=True
            ),
      ])
    ])
])

@app.callback(
    Output('plot', 'figure'),
    [Input('variables', 'value'),  Input('checklist', 'value')])

def update_graph(fig_name, continents):
    if fig_name == 'gdp per capita VS total deaths per million':
        mask = test.continent.isin(continents)
        fig1 = px.scatter(test[mask], x='gdp_per_capita', y='total_deaths_per_million', color='location',
                          size='population', size_max=40, hover_name='location',
                          title='gdp per capita VS total deaths per million in OECD+ countries by continent (size population)',
                          height=800)
        fig1.update_layout(
            xaxis_title="<b> gdp_per_capita <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig1
    
    if fig_name == 'gdp per capita VS total deaths per million and health expenditure':
        mask = test.continent.isin(continents)
        fig2 = px.scatter(test[mask], x='gdp_per_capita', y='total_deaths_per_million', color='location',
                          size='health_expenditure', size_max=40, hover_name='location',
                          title='gdp per capita VS total deaths per million in OECD+ countries by continent(size health expenditure per capita)',
                          height=800)
        fig2.update_layout(
            xaxis_title="<b> gdp_per_capita <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continent <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig2
    
    if fig_name == 'health expenditure VS total deaths per million':
        mask = test.continent.isin(continents)
        fig3 = px.scatter(test[mask], x='health_expenditure', y='total_deaths_per_million', color='location',
                          size='population', size_max=40, hover_name='location',
                          title='health expenditure (US$ per capita) VS total deaths per million in OECD+ countries by continent (size population)',
                          height=800)
        fig3.update_layout(
            xaxis_title="<b> health_expenditure (US$ per capita) <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig3
    
    if fig_name == 'population density VS total deaths per million':
        mask = test.continent.isin(continents)
        fig4 = px.scatter(test[mask], x='population_density', y='total_deaths_per_million', color='location',
                          size='population', size_max=40, hover_name='location',
                          title='population_density VS total deaths per million in OECD+ countries by continent (size population)',
                          height=800)
        fig4.update_layout(
            xaxis_title="<b> population_density <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig4
    
    if fig_name == 'health expenditure VS private health expenditure':
        mask = test.continent.isin(continents)
        fig5 = px.scatter(test[mask], x='health_expenditure', y='private_health_percent', color='location',
                          size='population', size_max=40, hover_name='location',
                          title='health expenditure VS private health expenditure (percent) in OECD+ countries by continent (size population)',
                          height=800)
        fig5.update_layout(
            xaxis_title="<b> health_expenditure <b>",
            yaxis_title="<b> private_health_percent <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig5
    
    if fig_name == 'hospital beds per thousand VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig6 = px.scatter(test[mask], x='hospital_beds_per_thousand', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='hospital beds per thousand VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig6.update_layout(
            xaxis_title="<b> hospital_beds_per_thousand <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig6
    
    if fig_name == 'medical_doctors_per10k VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig7 = px.scatter(test[mask], x='medical_doctors_per10k', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='medical doctors per 10k VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig7.update_layout(
            xaxis_title="<b> medical_doctors_per10k <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig7
    
    if fig_name == 'nursing_midwifery_per10k VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig8 = px.scatter(test[mask], x='nursing_midwifery_per10k', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='nursing midwifery per 10k VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig8.update_layout(
            xaxis_title="<b> nursing_midwifery_per10k <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig8
    
    if fig_name == 'aged_70_older VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig9 = px.scatter(test[mask], x='aged_70_older', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='aged 70 older VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig9.update_layout(
            xaxis_title="<b> aged_70_older <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig9
    
    if fig_name == 'population_density VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig10 = px.scatter(test[mask], x='population_density', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='population density VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig10.update_layout(
            xaxis_title="<b> population_density <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig10
    
    if fig_name == 'male_smokers VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig11 = px.scatter(test[mask], x='male_smokers', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='male smokers VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig11.update_layout(
            xaxis_title="<b> male_smokers <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig11
    
    if fig_name == 'TOTAL_VACCINATIONS_PER100 VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig12 = px.scatter(test[mask], x='TOTAL_VACCINATIONS_PER100', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='total vaccinatios per 100 VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig12.update_layout(
            xaxis_title="<b> TOTAL_VACCINATIONS_PER100 <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig12
    
    if fig_name == 'private_health_percent VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig13 = px.scatter(test[mask], x='private_health_percent', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='private health percent VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig13.update_layout(
            xaxis_title="<b> private_health_percent <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig13
    
    if fig_name == 'cardiovasc_death_rate VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig14 = px.scatter(test[mask], x='cardiovasc_death_rate', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='cardiovasc death rate VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig14.update_layout(
            xaxis_title="<b> cardiovasc_death_rate <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig14
    
    if fig_name == 'diabetes_prevalence VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig15 = px.scatter(test[mask], x='diabetes_prevalence', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='diabetes prevalence VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig15.update_layout(
            xaxis_title="<b> diabetes_prevalence <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig15
    
    if fig_name == 'human_development_index VS cumulative_estimated_daily_excess_deaths':
        mask = test.continent.isin(continents)
        fig16 = px.scatter(test[mask], x='human_development_index', y='cumulative_estimated_daily_excess_deaths_per_100k', color='location',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='human development index VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig16.update_layout(
            xaxis_title="<b> human_development_index <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig16

        
app.run_server(debug=True,
           use_reloader=False
          )
Dash is running on http://127.0.0.1:8050/

Dash is running on http://127.0.0.1:8050/

 * Serving Flask app '__main__' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on

Mismos gráficos agrupados por continentes, no por paises, para una visualización diferente, menor zoom.

In [11]:
from dash import dcc, html, Dash
import pandas as pd
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import numpy as np
from plotly.subplots import make_subplots
import plotly.express as px

app = Dash()
figs = ['gdp per capita VS total deaths per million', 'gdp per capita VS total deaths per million and health expenditure',
        'health expenditure VS total deaths per million', 'population density VS total deaths per million',
        'health expenditure VS private health expenditure',
        'hospital beds per thousand VS cumulative_estimated_daily_excess_deaths',
        'medical_doctors_per10k VS cumulative_estimated_daily_excess_deaths',
        'nursing_midwifery_per10k VS cumulative_estimated_daily_excess_deaths',
        'aged_70_older VS cumulative_estimated_daily_excess_deaths',
        'population_density VS cumulative_estimated_daily_excess_deaths',
        'male_smokers VS cumulative_estimated_daily_excess_deaths',
        'TOTAL_VACCINATIONS_PER100 VS cumulative_estimated_daily_excess_deaths',
        'private_health_percent VS cumulative_estimated_daily_excess_deaths',
        'cardiovasc_death_rate VS cumulative_estimated_daily_excess_deaths',
        'diabetes_prevalence VS cumulative_estimated_daily_excess_deaths',
        'human_development_index VS cumulative_estimated_daily_excess_deaths']

app.layout = html.Div([
    html.Div([
        dcc.Graph(id='plot'),

        html.Div([
            dcc.Dropdown(
                id='variables',
                options=[{'label': i, 'value': i} for i in figs],
                value=figs[0]
            ),
      ])
    ])
])

@app.callback(
    Output('plot', 'figure'),
    [Input('variables', 'value')])

def update_graph(fig_name):
    if fig_name == 'gdp per capita VS total deaths per million':
        fig1 = px.scatter(test, x='gdp_per_capita', y='total_deaths_per_million', color='continent',
                          size='population', size_max=40, hover_name='location',
                          title='gdp per capita VS total deaths per million in OECD+ countries by continent (size population)',
                          height=800)
        fig1.update_layout(
            xaxis_title="<b> gdp_per_capita <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig1
    
    if fig_name == 'gdp per capita VS total deaths per million and health expenditure':
        fig2 = px.scatter(test, x='gdp_per_capita', y='total_deaths_per_million', color='continent',
                          size='health_expenditure', size_max=40, hover_name='location',
                          title='gdp per capita VS total deaths per million in OECD+ countries by continent(size health expenditure per capita)',
                          height=800)
        fig2.update_layout(
            xaxis_title="<b> gdp_per_capita <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continent <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig2
    
    if fig_name == 'health expenditure VS total deaths per million':
        fig3 = px.scatter(test, x='health_expenditure', y='total_deaths_per_million', color='continent',
                          size='population', size_max=40, hover_name='location',
                          title='health expenditure (US$ per capita) VS total deaths per million in OECD+ countries by continent (size population)',
                          height=800)
        fig3.update_layout(
            xaxis_title="<b> health_expenditure (US$ per capita) <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig3
    
    if fig_name == 'population density VS total deaths per million':
        fig4 = px.scatter(test, x='population_density', y='total_deaths_per_million', color='continent',
                          size='population', size_max=40, hover_name='location',
                          title='population_density VS total deaths per million in OECD+ countries by continent (size population)',
                          height=800)
        fig4.update_layout(
            xaxis_title="<b> population_density <b>",
            yaxis_title="<b> total_deaths_per_million <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig4
    
    if fig_name == 'health expenditure VS private health expenditure':
        fig5 = px.scatter(test, x='health_expenditure', y='private_health_percent', color='continent',
                          size='population', size_max=40, hover_name='location',
                          title='health expenditure VS private health expenditure (percent) in OECD+ countries by continent (size population)',
                          height=800)
        fig5.update_layout(
            xaxis_title="<b> health_expenditure <b>",
            yaxis_title="<b> private_health_percent <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig5
    
    if fig_name == 'hospital beds per thousand VS cumulative_estimated_daily_excess_deaths':
        fig6 = px.scatter(test, x='hospital_beds_per_thousand', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='hospital beds per thousand VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig6.update_layout(
            xaxis_title="<b> hospital_beds_per_thousand <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig6
    
    if fig_name == 'medical_doctors_per10k VS cumulative_estimated_daily_excess_deaths':
        fig7 = px.scatter(test, x='medical_doctors_per10k', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='medical doctors per 10k VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig7.update_layout(
            xaxis_title="<b> medical_doctors_per10k <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig7
    
    if fig_name == 'nursing_midwifery_per10k VS cumulative_estimated_daily_excess_deaths':
        fig8 = px.scatter(test, x='nursing_midwifery_per10k', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='nursing midwifery per 10k VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig8.update_layout(
            xaxis_title="<b> nursing_midwifery_per10k <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig8
    
    if fig_name == 'aged_70_older VS cumulative_estimated_daily_excess_deaths':
        fig9 = px.scatter(test, x='aged_70_older', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='aged 70 older VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig9.update_layout(
            xaxis_title="<b> aged_70_older <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig9
    
    if fig_name == 'population_density VS cumulative_estimated_daily_excess_deaths':
        fig10 = px.scatter(test, x='population_density', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='population density VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig10.update_layout(
            xaxis_title="<b> population_density <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig10
    
    if fig_name == 'male_smokers VS cumulative_estimated_daily_excess_deaths':
        fig11 = px.scatter(test, x='male_smokers', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='male smokers VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig11.update_layout(
            xaxis_title="<b> male_smokers <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig11
    
    if fig_name == 'TOTAL_VACCINATIONS_PER100 VS cumulative_estimated_daily_excess_deaths':
        fig12 = px.scatter(test, x='TOTAL_VACCINATIONS_PER100', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='total vaccinatios per 100 VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig12.update_layout(
            xaxis_title="<b> TOTAL_VACCINATIONS_PER100 <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig12
    
    if fig_name == 'private_health_percent VS cumulative_estimated_daily_excess_deaths':
        fig13 = px.scatter(test, x='private_health_percent', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='private health percent VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig13.update_layout(
            xaxis_title="<b> private_health_percent <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig13
    
    if fig_name == 'cardiovasc_death_rate VS cumulative_estimated_daily_excess_deaths':
        fig14 = px.scatter(test, x='cardiovasc_death_rate', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='cardiovasc death rate VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig14.update_layout(
            xaxis_title="<b> cardiovasc_death_rate <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig14
    
    if fig_name == 'diabetes_prevalence VS cumulative_estimated_daily_excess_deaths':
        fig15 = px.scatter(test, x='diabetes_prevalence', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='diabetes prevalence VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig15.update_layout(
            xaxis_title="<b> diabetes_prevalence <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig15
    
    if fig_name == 'human_development_index VS cumulative_estimated_daily_excess_deaths':
        fig16 = px.scatter(test, x='human_development_index', y='cumulative_estimated_daily_excess_deaths_per_100k', color='continent',
                          size='health_expenditure', size_max=30, hover_name='location',
                          title='human development index VS cumulative estimated daily excess deaths per 100k in OECD+ countries by continent (size health expenditure)',
                          height=800)
        fig16.update_layout(
            xaxis_title="<b> human_development_index <b>",
            yaxis_title="<b> cumulative_estimated_daily_excess_deaths_per_100k <b>",
            legend_title="<b> Continents <b>",        
            xaxis = dict(
                showgrid=True,
                ticks="",
                showline = False,
                gridcolor = 'white'
            )
        )
        return fig16

        
app.run_server(debug=True,
           use_reloader=False
          )
Dash is running on http://127.0.0.1:8050/

Dash is running on http://127.0.0.1:8050/

Dash is running on http://127.0.0.1:8050/

 * Serving Flask app '__main__' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: on
In [12]:
test_2 = test[["gdp_per_capita", "health_expenditure", "hospital_beds_per_thousand",
               "medical_doctors_per10k", "nursing_midwifery_per10k",
               "total_deaths_per_million", "continent", "location"]].copy()

test_2["continent"].replace({"Oceania": 1, "Europe": 2, "North America": 3,
                             "South America": 4, "Asia": 5}, inplace=True)

fig = px.parallel_coordinates(test_2, dimensions=["medical_doctors_per10k",
                                                  "health_expenditure",
                                                  "nursing_midwifery_per10k",
                                                  "total_deaths_per_million"],
                             color="continent", range_color=[0.5, 5.5],
                             color_continuous_scale=[(0.00, "red"),   (0.2, "red"),
                                                     (0.2, "green"), (0.4, "green"),
                                                     (0.4, "blue"),  (0.6, "blue"),
                                                     (0.6, "yellow"),  (0.8, "yellow"),
                                                     (0.8, "orange"),  (1.00, "orange")],
                             width =1000, height=500)

fig.update_layout(coloraxis_colorbar=dict(
    title="continent",
    tickvals=[1,2,3,4,5],
    ticktext=['Oceania', 'Europe', 'North America', 'South America', 'Asia'],
    lenmode="pixels", len=300,
))
fig.show()
In [13]:
fig = px.parallel_coordinates(test_2, dimensions=["gdp_per_capita",
                                                  "health_expenditure",
                                                  "hospital_beds_per_thousand",
                                                  "total_deaths_per_million"],
                             color="continent", range_color=[0.5, 5.5],
                             color_continuous_scale=[(0.00, "red"),   (0.2, "red"),
                                                     (0.2, "green"), (0.4, "green"),
                                                     (0.4, "blue"),  (0.6, "blue"),
                                                     (0.6, "yellow"),  (0.8, "yellow"),
                                                     (0.8, "orange"),  (1.00, "orange")],
                             width =1000, height=500)

fig.update_layout(coloraxis_colorbar=dict(
    title="continent",
    tickvals=[1,2,3,4,5],
    ticktext=['Oceania', 'Europe', 'North America', 'South America', 'Asia'],
    lenmode="pixels", len=300,
))
fig.show()
In [ ]: